#!/bin/bash
set -xeuo pipefail
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
cd ${BASE_DIR}

mkdir -p pkg/data
mkdir -p pkg/ro
#docker pull erichough/nfs-server:2.2.1
#docker pull gists/nfs-server:2.4.3
:<<EOF
docker run \
    -d \
    --name nfs-server \
    --cap-add=SYS_ADMIN,SETPCAP \
    -p 2049:2049 \
    -v /your/path:/nfs-share \
    -e "NFS_DOMAIN=ip" # The visitor IP range
    gists/nfs-server
EOF

#nfsd.sh
chmod +x *.sh
#
docker rm -f nfs-server
docker run -it --name nfs-server --user=root --cap-add=ALL -p 2049:2049 -v $(pwd)/pkg:/nfs-share -v $(pwd)/exports:/etc/exports -v $(pwd)/nfsd.sh:/bin/nfsd.sh -e "NFS_DOMAIN=*" gists/nfs-server:2.4.3

# nfs v4(pwd)
# 客户端
:<<EOF
只读、 读写[可读写的权限]
$ docker exec -it nfs-server sh -c "ls /nfs-share -l"
total 8
drwxrwxrwx    2 1000     1000          4096 Dec  7 08:51 data
drwxr-xr-x    2 1000     1000          4096 Dec  7 08:14 ro

===
mkdir ~/nfs/share
mkdir ~/nfs/data
sudo mount -v -t nfs -o vers=4,port=2049 127.0.0.1:/ro ~/nfs/share
sudo mount -v -t nfs -o vers=4,port=2049 127.0.0.1:/data ~/nfs/data

sudo umount ~/nfs/share
sudo umount ~/nfs/data
EOF

#docker rm -f nfs-server 
echo "done"
